import axios from '@/api/http.js'
import md5 from 'js-md5'

const getFulTime = () => {
  const time = new Date()
  const year = time.getFullYear()
  const month = (time.getMonth() + 1) > 9 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1)
  const day = time.getDate() > 9 ? time.getDate() : '0' + time.getDate()
  const hours = time.getHours() > 9 ? time.getHours() : '0' + time.getHours()
  const minutes = time.getMinutes() > 9 ? time.getMinutes() : '0' + time.getMinutes()
  const tody = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes

  return tody
}

const apiList = {
  getArticleList(params) {
    const sign = {
      key: "uqQ8&2Kot",
      keywords: params.keywords ? params.keywords : null,
      page: params.page,
      page_num: params.pageNum,
      time: getFulTime()
    }

    return axios({
      url: `https://www.krqia.cn/api/code/list?page=${params.page}&page_num=${params.pageNum}&keywords=${params.keywords}`,
      method: 'get',
      headers: {
        sign: md5(JSON.stringify(sign))
      }
    })
  }
}

export default apiList
